﻿using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using UnitOfWorkCore.Domain.Abstractions;
using UnitOfWorkCore.Domain.ToolKits.Extensions;
using UnitOfWorkCore.Infrastructure.Context;

namespace UnitOfWorkCore.Infrastructure
{
    /// <summary>
    /// 实现泛型仓储
    /// </summary>
    /// <typeparam name="TEntity"></typeparam>
    public class Repository<TEntity> : Repository<TEntity, Guid>, IRepository<TEntity>
        where TEntity : Entity<Guid>, IAggregateRoot
    {
        public Repository(AppDbContext Mddb) : base(Mddb)
        {
        }
    }

    /// <summary>
    /// 实现泛型仓储
    /// </summary>
    /// <typeparam name="TEntity"></typeparam>
    /// <typeparam name="TKey"></typeparam>
    public class Repository<TEntity, TKey> : IRepository<TEntity, TKey>
    where TEntity : Entity<TKey>, IAggregateRoot where TKey : notnull
    {
        private readonly AppDbContext _Mddb;
        public virtual DbSet<TEntity> Entity => _Mddb.Set<TEntity>();
        public Repository(AppDbContext Mddb) => _Mddb = Mddb;

        public Task<bool> DeleteArray(List<TKey> array)
        {
            throw new NotImplementedException();
        }

        public Task<bool> DeleteSingleData()
        {
            throw new NotImplementedException();
        }

        public Task<bool> InsertManyData(List<TEntity> array)
        {
            throw new NotImplementedException();
        }

        public Task<Tuple<bool, int>> InsertOrUpdateSingleData(TEntity data)
        {
            throw new NotImplementedException();
        }

        public async Task InsertSingleData(TEntity data)
        {
            await Entity.AddAsync(data);
        }

        public Task<int> QueryCount(Expression<Func<TEntity, bool>> expression)
        {
            throw new NotImplementedException();
        }

        public Task<bool> QueryExist(Expression<Func<TEntity, bool>> expression)
        {
            throw new NotImplementedException();
        }

        public Task<Tuple<List<TEntity>, int>> QueryPageData(Expression<Func<TEntity, bool>> expression)
        {
            throw new NotImplementedException();
        }

        public Task<Tuple<List<TEntity>, int>> QueryPageData(Expression<Func<TEntity, bool>> expression, string sort, string order)
        {
            throw new NotImplementedException();
        }

        public Task<Tuple<List<TEntity>, int>> QueryPageData(Expression<Func<TEntity, bool>> expression, Func<TEntity, dynamic> sort, string sortType)
        {
            throw new NotImplementedException();
        }

        public Task<Tuple<List<TEntity>, int>> QueryPageData(Expression<Func<TEntity, bool>> expression, IEnumerable<Func<TEntity, dynamic>> sorts, string sortType)
        {
            throw new NotImplementedException();
        }

        public Task<IPageInfo<dynamic>> QueryPageData(Expression<Func<TEntity, bool>> expression, Func<TEntity, dynamic> sort)
        {
            throw new NotImplementedException();
        }

        public Task<TEntity> QuerySingleData(TKey id)
        {
            throw new NotImplementedException();
        }

        public Task<TEntity> QuerySingleData(Expression<Func<TEntity, bool>> expression)
        {
            throw new NotImplementedException();
        }

        public Task<TEntity> QuerySingleData(Expression<Func<TEntity, bool>> expression, Func<TEntity, dynamic> sort)
        {
            throw new NotImplementedException();
        }

        public Task<TEntity> QuerySingleData(Expression<Func<TEntity, bool>> expression, IEnumerable<Func<TEntity, dynamic>> sorts, string sortType)
        {
            throw new NotImplementedException();
        }

        public async Task<List<TEntity>> QueryTableList(Expression<Func<TEntity, bool>> expression)
        {
            return await _Mddb.Set<TEntity>().Where(expression).ToListAsync();
        }

        public Task<List<TResult>> QueryTableList<TResult>(Expression<Func<TEntity, bool>> expression, Expression<Func<TEntity, TResult>> result)
        {
            throw new NotImplementedException();
        }

        public Task UpdateManyData(List<TEntity> array)
        {
            throw new NotImplementedException();
        }

        public Task UpdateSingleData(TEntity data)
        {
            throw new NotImplementedException();
        }
    }
}
